/*
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 */
function onDeleteShippingMethod(url, ShippingMethodCode, resp) {
	var isOK = -1;
	
	if(!confirm('Are you sure you want to delete the Shipping Method with Code:' + ShippingMethodCode)) {
		return false;
	}
	
	new Ajax.Request(url, {
	  method: 'post',
	  asynchronous: false,
	  parameters:'act=delShippingMethod&id=' + ShippingMethodCode,
	  onSuccess: function(transport) {
			var response = transport.responseText || "";
			var pos=response.indexOf('<!');
			content=response.substring(0,pos);
		    	//alert(content);
			
			//alert(response);
			
			obj = content.evalJSON();

    		if(obj == null) {
    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
		
    		$(resp).update(obj.message);
		}
	});

	$(resp).style.display = 'inherit';
	Fat.fade_element(resp, null, 1500, null, null);

	if(isOK == 0) {
		rowID = ShippingMethodCode;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
		
	}				
}
function onAddNewShippingMethod(frmID, msgDiv, listtable) {
	var newId = '';
	
	$(frmID).request( {
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  		onComplete: function(transport) { 
			  	var response = transport.responseText || "";
				var pos=response.indexOf('<!');
				content=response.substring(0,pos);
		    	//alert(content);
		    	
		    	$(msgDiv).innerHTML = '';

		    	if(content != "") {
		    		//alert(response);
		    		obj = content.evalJSON();
		    		
		    		if(obj == null) {
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + response);
		    		}
		    		
			    	if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
				    
				    if(obj.ID != -1) {
					    if(listtable != null && $(listtable) != null) {
							sClassName = 'newrow';
						
							str = '<tr id="' + obj.ID + '" class="newrow">';
							str +=	'<td scope="row" style="text-align: left">' + obj.ID + '</th>';
							str +=	'<td>'    + obj.name + '</td>';
							str +=	'	<td style="text-align: right">' + obj.delivery_cost + obj.symbol_left + '</td>';
							str +=	'<td>'    + obj.symbol_left + '</td>';
							if(obj.status ==1) {
									str += '<td align="center">' + 'x' + '</td>';
							} else {
									str += '&nbsp;' ;
							}
							str +=	'	<td style="text-align: center"><a href="?module=BgcmsWebshop&sub1=shippingmethod&act=editshippingmethod&id=' + obj.ID + '" '; 
							str +=	'			class="edit">Edit</td>';
							str +=	'	<td style="text-align: center"><a onclick="onDeleteShippingMethod(\'?module=BgcmsWebshop&sub1=shippingmethod\', \'' + obj.ID  + '\', \'ajaxResponse1\')"'; 
							str +=	'			class="delete">Delete</td>';
							str +=	'</tr>';
							
							$(listtable).innerHTML += str;
								
							newId = obj.ID;
						    	
					    }
		    		}
		    	}
	  		}
		});

	$(msgDiv).style.display = 'block';
	Fat.fade_element(msgDiv, null, 1500, null, null);
	if(newId != '') {
		Fat.fade_element(newId);
		$(frmID).reset();
	}
	//revent submit page
	return false;
}